import tensorflow as tf
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report


def r_mnist():
    mnist = tf.keras.datasets.mnist
    (train_x, train_y), (test_x, test_y) = mnist.load_data()
    knn_model = KNeighborsClassifier(n_neighbors=10,
                                     n_jobs=-1)
    train_x = train_x.reshape((train_x.shape[0], 784))
    test_x = test_x.reshape((test_x.shape[0], 784))
    knn_model.fit(train_x, train_y)
    print('[info]:正在生成报告')
    print(classification_report(test_y, knn_model.predict(test_x)))


if __name__ == '__main__':
    r_mnist()